Vue.component('update', {
    template: `
      <el-dialog title="修改" width="900px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
        <el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
            <el-row >
              <el-col :span="24">
                <el-form-item label="所属矿机" prop="linkcata_id">
                  <el-select   style="width:100%" v-model="form.pid" filterable clearable placeholder="请选择所属矿机">
                    <el-option v-for="(item,i) in pinfo" :key="i" :label="item.name" :value="item.id"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row >
            <el-col :span="24">
              <el-form-item label="套餐名称" prop="name">
                <el-input  v-model="form.name" autoComplete="off" clearable placeholder="简体"></el-input>

                <el-input  v-model="form.t_name" autoComplete="off" clearable placeholder="繁体"></el-input>

                <el-input  v-model="form.e_name" autoComplete="off" clearable placeholder="英文"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="标签名称" prop="label">
                <el-input  v-model="form.label" autoComplete="off" clearable placeholder="简体"></el-input>

                <el-input  v-model="form.t_label" autoComplete="off" clearable placeholder="繁体"></el-input>

                <el-input  v-model="form.e_label" autoComplete="off" clearable placeholder="英文"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="矿机图标" prop="pic">
                <Upload v-if="show" size="small"  file_type="image" filterable :image.sync="form.pic"></Upload>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="矿机图标(繁体)" prop="e_pic">
                <Upload v-if="show" size="small"  file_type="image" filterable :image.sync="form.e_pic"></Upload>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="矿机图标(英文)" prop="t_pic">
                <Upload v-if="show" size="small"  file_type="image" filterable :image.sync="form.t_pic"></Upload>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="购入币种:">
                <el-radio-group v-model="form.currency">
                  <el-radio :label="1">USDT</el-radio>
                  <el-radio :label="2">BABM</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24" >
              <el-form-item label="购买单价" prop="price">
                <el-input typt="number" v-model="form.money" autoComplete="off" filterable clearable placeholder="请输入价格"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24" >
              <el-form-item label="个人最大持有量" prop="max_possess">
                <el-input typt="number" v-model="form.max_possess" autoComplete="off" filterable clearable placeholder="请输入个人最大持有量 -1:为不限制"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="可出售数量" prop="available_for_sale">
                <el-input typt="number" v-model="form.available_for_sale" autoComplete="off" filterable clearable placeholder="请输入可出售数量 -1为不限制"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="矿机状态:">
                <el-radio-group v-model="form.type">
                  <el-radio :label="1">预售中</el-radio>
                  <el-radio :label="2">出售中</el-radio>
                  <el-radio :label="3">暂停出售</el-radio>
                  <el-radio :label="4">已出售完</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="矿机算力" prop="arithmetical">
                <el-input typt="number" v-model="form.arithmetical" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
                <el-col :span="24">
                  <el-form-item label="赠送直推算力" prop="push_arithmetical">
                    <el-input typt="number" v-model="form.push_arithmetical" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row >
                <el-col :span="24">
                  <el-form-item label="赠送间推算力" prop="indirect_arithmetical">
                    <el-input typt="number" v-model="form.indirect_arithmetical" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="质押币种:">
                <el-radio-group v-model="form.pledge_currency">
                  <el-radio :label="1">USDT</el-radio>
                  <el-radio :label="2">BABM</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="质押金额" prop="pledge_money">
                <el-input typt="number" v-model="form.pledge_money" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="质押倍数" prop="pledge_multiple">
                <el-input typt="number" v-model="form.pledge_multiple" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row >
            <el-col :span="24">
              <el-form-item label="返回质押比例 %" prop="return_pledge">
                <el-input typt="number" v-model="form.return_pledge" autoComplete="off" filterable clearable placeholder="请输入数量"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button :size="size" :loading="loading" type="primary" @click="submit" >
                <span v-if="!loading">确 定</span>
                <span v-else>提 交 中...</span>
            </el-button>
            <el-button :size="size" @click="closeForm">取 消</el-button>
        </div>
    </el-dialog>
    `,
    components:{
    },
    props: {
        show: {
            type: Boolean,
            default: false
        },
        size: {
            type: String,
            default: 'small'
        },
        info: {
            type: Object,
        },
    },
    watch:{
        show(val){
            if(val){
                axios.post(base_url + '/Mining/getList').then(res => {
                    if(res.data.status == 200){
                        this.pinfo = res.data.data
                    }
                })
            }
        }
    },
    data(){
        return {
            form: {
                pid:'请选择所属矿机',
                name:'',
                e_name:'',
                t_name:'',
                label:'',
                e_label:'',
                t_label:'',
                pic:'',
                e_pic:'',
                t_pic:'',
                currency:1,
                money:'',
                max_possess:'',
                quantity_sold:'',
                available_for_sale:'',
                type:1,
                arithmetical:'',
                push_arithmetical:0,
                indirect_arithmetical:0,
                pledge_money:'',
                pledge_multiple:'',
                return_pledge:'',
                pledge_currency:'',
            },
            loading:false,
            pinfo:[],
            rules: {
                name:[
                    {required: true, message: '矿机名称不能为空', trigger: 'blur'},
                ],
                e_name:[
                    {required: true, message: '矿机名称不能为空', trigger: 'blur'},
                ],
                t_name:[
                    {required: true, message: '矿机名称不能为空', trigger: 'blur'},
                ],
                label:[
                    {required: true, message: '标签不能为空', trigger: 'blur'},
                ],
                e_label:[
                    {required: true, message: '标签不能为空', trigger: 'blur'},
                ],
                t_label:[
                    {required: true, message: '标签不能为空', trigger: 'blur'},
                ],
                pic:[
                    {required: true, message: '请上传矿机图标', trigger: 'blur'},
                ],
                e_pic:[
                    {required: true, message: '请上传矿机图标', trigger: 'blur'},
                ],
                t_pic:[
                    {required: true, message: '请上传矿机图标', trigger: 'blur'},
                ],
                money:[
                    {required: true, message: '请输入套餐单价', trigger: 'blur'},
                ],
                duration:[
                    {required: true, message: '请输入套餐有效日期', trigger: 'blur'},
                ],
                daily_release:[
                    {required: true, message: '请输入套餐每日释放数量', trigger: 'blur'},
                ],
            }
        }
    },
    methods: {
        open(){
            this.form = this.info
        },
        submit(){
            this.$refs['form'].validate(valid => {
                if(valid) {
                    this.loading = true
                    axios.post(base_url + '/MiningArithmetical/edit',this.form).then(res => {
                        if(res.data.status == 200){
                            this.$message({message: res.data.msg, type: 'success'})
                            this.$emit('refesh_list')
                            this.closeForm()
                        }else{
                            this.loading = false
                            this.$message.error(res.data.msg)
                        }
                    }).catch(()=>{
                        this.loading = false
                    })
                }
            })
        },
        closeForm(){
            this.$emit('update:show', false)
            this.loading = false
            if (this.$refs['form']!==undefined) {
                this.$refs['form'].resetFields()
            }
        },
    }
})
